define([
  'views/View',
  'views/media/VideoAlbumModal',
  'hbs!template/media/video-preview'
], function(View, VideoAlbumModal, template){

  var ImagePreview = View.extend({
    template: template,
    
    events: {
      "click .thumbnail": "modalPreview"
    },

    // Flags to be used in template and events handlers.
    flags: {
      modal: false      // This flag will render a check doing this photo checkable.
    },
    
    initialize: function(options) {
      options || (options = {});
      View.prototype.initialize.call(this, options);

      if(options.flags) {
        // Set the flags from the options
        this.flags = options.flags;
      }
    },

    render: function() {
      View.prototype.render.call(this);
      
      return this;
    },

    modalPreview: function() {
      if(this.flags.modal) {
        console.log("Modal preview calling");
        var position = this.collection.indexOf(this.model);
        var modal = new VideoAlbumModal({models: this.collection.pagination.models(), position: position});
        modal.render();
      }
    },

    getRenderData: function() {
      var data = View.prototype.getRenderData.call(this);
      data._flags = this.flags;
      console.log(data);
      return data;
    }
    
  });

  return ImagePreview;
});